package com.st.security.config;

import com.st.security.base.result.STResult;
import lombok.SneakyThrows;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @创建人: 放生
 * @创建时间: 2022/4/6
 * @描述: 退出登入处理器，可以在这里删除 Redis中或者session的相关用户信息
 */
@Component("customLogoutHandler")
public class CustomLogoutHandler implements LogoutHandler {

    @SneakyThrows
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        STResult result = STResult.ok("退出成功");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(result.toJsonString());
    }
}
